import express from 'express';
import multer from 'multer';
import path from 'path';
import {PUBLIC_ASSETS_PATH} from '@/config/dev';
import {botController} from '../controller/bot';
import {uploadController} from '../controller/upload';


const upload = multer({
    storage: multer.diskStorage({
        destination: (req, file, cb) => {
            cb(null, PUBLIC_ASSETS_PATH + '/static/');
        },
        filename: function (req, file, cb) {
            const uniqueSuffix = Date.now() + '-' + Math.round(Math.random() * 1E9);
            const ext = path.extname(file.originalname);
            const filename = path.basename(file.originalname, ext);
            cb(null, filename + '-' + uniqueSuffix + ext);
        }
    })
});


export const apiRouter = express.Router();
apiRouter.post('/bot/summary-content/stream', botController.summaryContentWithStream);
apiRouter.post('/upload', upload.array('file'), uploadController.upload);
